﻿package com.javaPattern.DynamicProxy;

import java.lang.reflect.*;

// 用动态代理实现
public class PassengerProxy1 implements InvocationHandler {
	public Object obj;

	// 把obj交给代理类
	public  Object setObj(Object obj) {
		this.obj = obj;
		return Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj
				.getClass().getInterfaces(), this);
	}

	@Override
	// 这里是真正要调用的方法
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		System.out.println("先去代售点");
		method.invoke(obj, args);
		System.out.println("返回到代售点");
		return obj;
	}
}
